package com.boil.qz.safekavass.weixin.controller;

import com.boil.util.BaseController;
import com.boil.util.Constants;
import oracle.jrockit.jfr.events.RequestableEventEnvironment;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by ChenYong on 2017-05-17.
 * <br>
 * 微信网页授权 Controller。
 */
@Controller("WebpageAuthorizeController")
@RequestMapping("/weixin/webpage")
public class WebpageAuthorizeController extends BaseController {
    /**
     * 添加举报页面。
     *
     * @param model 模型
     * @return 添加举报页面
     */
    @RequestMapping(method = RequestMethod.GET, value = "/authorize.html")
    public String authorize(Model model, String page) {
        Map<String, String[]> paramMap = request.getParameterMap();
        Set<Map.Entry<String, String[]>> paramEntrySet = paramMap.entrySet();
        Iterator<Map.Entry<String, String[]>> paramEntryIterator = paramEntrySet.iterator();

        while (paramEntryIterator.hasNext()) {
            Map.Entry<String, String[]> paramEntry = paramEntryIterator.next();

            log.info("网页授权参数：{}--->{}", paramEntry.getKey(), Arrays.toString(paramEntry.getValue()));
        }

        if (StringUtils.isNotBlank(page)) {
            // 跳转至举报界面
            if (Constants.PAGE_REPORT.equals(page)) {
                return "/weixin/report/add";
            }
        }

        return "";
    }
}